package com.hkts.management.cargoapply.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.cargoapply.service.IHktsCargoApplyService;
import com.hkts.management.model.VO.HktsCargoApplyOnPCVo;
import com.hkts.management.utils.CustomPageUtils;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.cargoapply.entity.HktsCargoApply;

import java.util.List;

/**
 * @author hml
 * @since 2021-04-22
 */
@RestController
@RequestMapping("/order/hktsCargoApply")
@Api(tags = "报名管理接口")
public class HktsCargoApplyController {
    private final Logger logger = LoggerFactory.getLogger(HktsCargoApplyController.class);

    @Autowired
    public IHktsCargoApplyService iHktsCargoApplyService;

    /**
     * 分页查询数据
     *
     * @param page           分页信息
     * @param hktsCargoApply 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsCargoApplyPageList")
    public Result<Object> getHontUserList(Page<HktsCargoApply> page, HktsCargoApply hktsCargoApply) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsCargoApplyService.selectPage(page, hktsCargoApply)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsCargoApply 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsCargoApplySave")
    public Result<Object> hktsCargoApplySave(HktsCargoApply hktsCargoApply) {
        iHktsCargoApplyService.saveOrUpdate(hktsCargoApply);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsCargoApplyGetById")
    public Result<Object> hktsCargoApplyGetById(String id) {
        HktsCargoApply byId = iHktsCargoApplyService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsCargoApplyDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsCargoApplyService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsCargoApplyBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsCargoApplyService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 后台报名信息
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/getApplyInfo")
    @ApiOperation(value = "后台报名信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applyId", value = "报名Id", dataType = "String",required = true)
    })
    public  Result<HktsCargoApplyOnPCVo> getApplyInfo(String applyId){
        return iHktsCargoApplyService.getApplyInfo(applyId);
    }

}
